#include "StdAfx.h"
#include "Desired.h"

namespace MnistDigit
{
	size_t Desired::GetClassCount()
	{
		return 10;//count(0,1,2,3,4,5,6,7,8,9)=10
	}

	std::vector<double>& Desired::GetDesired(size_t classId)
	{
		return GetDesireds()[classId];
	}

	size_t Desired::FindClass(const std::vector<double>& output)
	{
		//bias
		const std::vector<double>::const_iterator result = std::max_element(
			output.begin(),
			output.end()-1);

		const size_t iMaxIndex = std::distance(output.begin(), result);
		assert(iMaxIndex<GetClassCount());
		return iMaxIndex;
	}

	std::vector< std::vector< double> >& Desired::GetDesireds()
	{
		static std::vector< std::vector< double> > desireds = InitDesired(GetClassCount(), -1.0, 1.0);
		return desireds;
	}

	std::vector<std::vector<double> > Desired::InitDesired(const size_t outputCount
		, const double minValue
		, const double maxValue)
	{
		std::vector<std::vector<double> > desireds(outputCount);

		for(size_t i=0; i<outputCount; ++i)
		{
			desireds[i].resize(outputCount);
			std::fill(desireds[i].begin(), desireds[i].end(), minValue);
			desireds[i][i]=maxValue;
		}
		return desireds;
	}

}
